home *** CD-ROM | disk | FTP | other *** search
/ 3D Games (Spidla) / 3dhry2.iso / Cube Drop 2001 1.0 / Camera.h < prev    next >
Encoding:
C/C++ Source or Header  |  2003-03-17  |  3.3 KB  |  164 lines

  1. #ifndef CAMERA_H
  2. #define CAMERA_H
  3.  
  4. #define PI 3.14159
  5.  
  6.  
  7. class Camera
  8. {
  9.     private:
  10.         GLfloat x, y, z;
  11.         float angle; //radians
  12.         float radius;
  13.         BOOL radiusLimiter;
  14.         BOOL heightLimiter;
  15.         float maxRadius, minRadius;
  16.         float maxHeight, minHeight;
  17.  
  18.     public:
  19.         // angle in radians
  20.         // positive z axis coming out of the screen
  21.         Camera(GLfloat ang, GLint rad, GLint yy)
  22.         {
  23.             heightLimiter = FALSE;
  24.             radiusLimiter = FALSE;
  25.             maxHeight = 200;
  26.             minHeight = -100;
  27.             maxRadius = 300;
  28.             minRadius = 12;
  29.             angle = ang;
  30.             radius = rad;
  31.             y = yy;
  32.             x=static_cast<GLfloat>(radius*cos(angle)+12.0f);
  33.             z=static_cast<GLfloat>(radius*sin(angle)-12.0f);
  34.         }
  35.  
  36.         ~Camera() {}
  37.  
  38.         void SetCamera(GLfloat ang, GLint rad, GLint yy)
  39.         {
  40.             angle = ang;
  41.             radius = rad;
  42.             x=static_cast<GLfloat>(radius*cos(angle)+12.0f);
  43.             z=static_cast<GLfloat>(radius*sin(angle)-12.0f);
  44.             y = yy;
  45.         }
  46.  
  47.         GLfloat getX() {return x;}
  48.         GLfloat getY() {return y;}
  49.         GLfloat getZ() {return z;}
  50.         void Up()
  51.         {
  52.             //dont let the camera get higher than maxHeight
  53.             //if it does, then move it back down
  54.             //until it gets all the way to minHeight
  55.             if(y <= maxHeight && !heightLimiter)
  56.             {
  57.                 if(y >= maxHeight)
  58.                     heightLimiter = TRUE;
  59.  
  60.                 y += 1.0f;                
  61.             }
  62.             else
  63.             {
  64.                 if(y <= minHeight)
  65.                     heightLimiter = FALSE;
  66.  
  67.                 y -= 1.0f;
  68.             }
  69.         }
  70.  
  71.         void Down()
  72.         {
  73.             //don't let the camera get lower than minHeight
  74.             //ifit does, then begin increasing it until it gets to maxHeight
  75.             if(y >= minHeight && !heightLimiter)
  76.             {
  77.                 if(y <= minHeight)
  78.                     heightLimiter = TRUE;
  79.  
  80.                 y -= 1.0f;
  81.             }
  82.             else
  83.             {
  84.                 if(y >= maxHeight)
  85.                     heightLimiter = FALSE;
  86.  
  87.                 y += 1.0f;
  88.             }
  89.         }
  90.  
  91.         void RotateC()
  92.         {
  93.             //keep the angle between 360 and -360
  94.             if(angle < -360)
  95.                 angle += 360;
  96.  
  97.             angle -= 0.1f;
  98.             x=static_cast<GLfloat>(radius*cos(angle)+12.0f);
  99.             z=static_cast<GLfloat>(radius*sin(angle)-12.0f);
  100.         }
  101.  
  102.         void RotateCC()
  103.         {
  104.             //keep the angle between 360 and -360
  105.             if(angle > 360)
  106.                 angle -= 360;
  107.  
  108.             angle += 0.1;
  109.             x=static_cast<GLfloat>(radius*cos(angle)+12.0f);
  110.             z=static_cast<GLfloat>(radius*sin(angle)-12.0f);
  111.         }
  112.  
  113.         void In()
  114.         {
  115.             //don't let the camera get closer to the y than minRadius
  116.             //if the radius gets down to 12, then increase it
  117.             //until it gets to the maximum radius
  118.             if(radius >= minRadius && !radiusLimiter)
  119.             {
  120.                 if(radius <= minRadius)
  121.                     radiusLimiter = TRUE;
  122.  
  123.                 radius -= 1.0f;
  124.             }
  125.             else
  126.             {
  127.                 if(radius >= maxRadius)
  128.                     radiusLimiter = FALSE;
  129.                 radius += 1.0f;
  130.  
  131.             }
  132.  
  133.             x=static_cast<GLfloat>(radius*cos(angle)+12.0f);
  134.             z=static_cast<GLfloat>(radius*sin(angle)-12.0f);                
  135.         }
  136.  
  137.         void Out()
  138.         {
  139.             //dont let the camera go further than maxRadius away from the y axis
  140.             //if it gets out to a radius of 100, then move it back in
  141.             //until it gets all the way back in to the minimum radius
  142.             if(radius <= maxRadius && !radiusLimiter)
  143.             {
  144.                 if(radius >= maxRadius)
  145.                     radiusLimiter = TRUE;
  146.  
  147.                 radius += 1.0f;                
  148.             }
  149.             else
  150.             {
  151.                 if(radius <= minRadius)
  152.                     radiusLimiter = FALSE;
  153.  
  154.                 radius -= 1.0f;
  155.             }
  156.  
  157.             x=static_cast<GLfloat>(radius*cos(angle)+12.0f);
  158.             z=static_cast<GLfloat>(radius*sin(angle)-12.0f);                
  159.         }
  160. };
  161.  
  162.  
  163.  
  164. #endif